import request from '../../untils/request.js'

const app = getApp()

Page({
    data: {
        bannerList: [],
        recommendList: [],
        topList: [],
    },
    onLoad: async function (options) {
        let bannerListData = await request(
            '/banner', {typr: 2})
        this.setData({
            bannerList: bannerListData.banners
        })
        // 推荐歌单数据
        let recommendListData = await request(
            '/personalized', {limit: 10})
        this.setData({
            recommendList: recommendListData.result
        })


        // 排行榜数据
        let index = 0;
        let resultArr = [];
        while (index < 5) {
            let topListData = await request(
                '/top/list', {idx: index++})
            let topListItem = {
                name: topListData.playlist.name,
                tracks: topListData.playlist.tracks.slice(0, 3)
            }
            resultArr.push(topListItem);
            this.setData({
                topList: resultArr
            })
        }
    },
    toRecommendSong() {
        wx.navigateTo({
            url:'/songPackage/pages/recommendSong/recommendSong'
        })
    },
    toOther(){
        wx.navigateTo({
            url:'/otherPackage/pages/other/other'
        })
    }
})

